/*
* Conditions Of Use
*
* This software was developed by employees of the Sigmatrix(Beijing) Corporation.
* This software is provided by sigmatrix as a service and is expressly
* provided "AS IS."  Sigmatrix MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
* AND DATA ACCURACY.  Sigmatrix does not warrant or make any representations
* regarding the use of the software or the results thereof, including but
* not limited to the correctness, accuracy, reliability or usefulness of
* the software.
*
* Permission to use this software is contingent upon your acceptance
* of the terms of this agreement.
*
*/
package com.sigmatrix.h5.dto;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.util.CollectionUtils;

/**
 *@ClassName: QRCodeError
 *@Description: 错误码信息
 *@author youjun
 *@date 2017年8月11日 下午3:49:21
 */
public class QRCodeError implements Serializable {

	/**
	 *@Fields serialVersionUID : TODO()
	 */
	private static final long serialVersionUID = -8240812882079046416L;

	/**错误的扫描码,原样返回,如:HTTP://ewewe*/
	private String qRCode;
	
	/**错误码级别,若码不存在,则该级别也为null*/
	private Integer qrCodeLevel;
	
	/**产品ID*/
	private Integer productId;
	
	/**错误消息*/
	private String errorMsg;
	
	/**错误的包装码或单品码*/
	private List<QRCodeError> childErrorCode = new ArrayList<QRCodeError>();

	public QRCodeError() {}
	
	/**
	 *@Title: QRCodeError
	 *@Description: TODO
	 *@param qRCode
	 *@param qrCodeLevel
	 *@param productId
	 *@param errorMsg
	 */
	public QRCodeError(String qRCode, Integer qrCodeLevel, Integer productId, String errorMsg) {
		super();
		this.qRCode = qRCode;
		this.qrCodeLevel = qrCodeLevel;
		this.productId = productId;
		this.errorMsg = errorMsg;
	}

	/**
	 *@Title: getNotRepetition
	 *@Description: 获取不重复的错误码
	 *@return List<QRCodeError>
	 *@author youjun
	 *@date 2017年8月24日 下午9:13:54
	 *@param qRCodeErrorList
	 *@return
	 */
	public static List<QRCodeError> getNotRepetition(final List<QRCodeError> qRCodeErrorList) {
		
		if(!CollectionUtils.isEmpty(qRCodeErrorList)) {
			final List<QRCodeError> notRepetition = new ArrayList<QRCodeError>();
			final Set<String> qRCodeSet = new HashSet<String>();
			for(final QRCodeError error:qRCodeErrorList) {
				if(qRCodeSet.add(error.getQRCode())) {
					notRepetition.add(error);
				}
			}
			return notRepetition;
		}
		return null;
	}
	
	

	public String getQRCode() {
		return qRCode;
	}

	public void setQRCode(String qRCode) {
		this.qRCode = qRCode;
	}

	/**
	 *@return the errorMsg
	 */
	public String getErrorMsg() {
		return errorMsg;
	}

	/**
	 *@param errorMsg the errorMsg to set
	 */
	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	/**
	 *@return the childErrorCode
	 */
	public List<QRCodeError> getChildErrorCode() {
		return childErrorCode;
	}

	/**
	 *@param childErrorCode the childErrorCode to set
	 */
	public void setChildErrorCode(List<QRCodeError> childErrorCode) {
		this.childErrorCode = childErrorCode;
	}

	/**
	 *@return the qrCodeLevel
	 */
	public Integer getQrCodeLevel() {
		return qrCodeLevel;
	}

	/**
	 *@param qrCodeLevel the qrCodeLevel to set
	 */
	public void setQrCodeLevel(Integer qrCodeLevel) {
		this.qrCodeLevel = qrCodeLevel;
	}

	/**
	 *@return the productId
	 */
	public Integer getProductId() {
		return productId;
	}

	/**
	 *@param productId the productId to set
	 */
	public void setProductId(Integer productId) {
		this.productId = productId;
	}
	
}
